package com.cleverest.cleverestdiary.validation;

import com.cleverest.cleverestdiary.anno.State;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class StateValidation implements ConstraintValidator<State, String>/*给哪个数据校验规则，校验的数据类型*/ {
    /**
     * 提供校验规则
     *
     * @param value   object to validate，将来要校验的数据
     * @param context context in which the constraint is evaluated
     * @return 如果返回false则校验不通过，返回true则通过
     */
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }
        if (value.equals("已发布") || value.equals("草稿")) {
            return true;
        }
        return false;
    }
}
